<template>
	<view>
		<view class="order-content">
			<van-skeleton title row="13" :loading="loading">
			<view style="margin-bottom: 40rpx;">
				
				<view class="detail-title">
					<text>记录信息</text>
				</view>
				<!-- <view class="detail-item">
					<text class="left">任务名称：</text>
					<view class="right-content">{{taskDetail['任务名称']}}</view>
				</view> -->
				<view class="content-item">
					<text class="item-name">申请类型：</text>
					<view class="right-content">{{ materialApplyType[recordInfo['申请类型']] }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">申请人：</text>
					<view class="right-content">{{ recordInfo['申请人员'] }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">申请单位：</text>
					<view class="right-content">{{ recordInfo['申请单位'] }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">申请时间：</text>
					<view class="right-content">{{ recordInfo['申请时间'] | formatTime }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">申请仓库：</text>
					<view class="right-content">{{ '申请仓库' }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">申请原因：</text>
					<view class="right-content">{{ recordInfo['申请原因'] }}</view>
				</view>
				<view class="content-item">
					<text class="item-name">审核状态：</text>
					<view class="right-content">{{ examineStatus[recordInfo['状态']] }}</view>
				</view>
				<view v-if="detail['审批状态'] == 2" class="content-item">
					<text class="item-name">状态：</text>
					<view class="right-content">{{ status }}</view>
				</view>
			</view>
			
			<view style="margin-bottom: 40rpx;">
				<view class="detail-title">
					<text>耗材清单</text>
				</view>
				
			</view>
			</van-skeleton>
		</view>
		<view class="apply-list-container">
			<list-item :applyList="detail['材料清单']"></list-item>
		</view>
		
	</view>
</template>

<script>
	import ListItem from '../components/listItem.vue'
	export default {
		components: {
			ListItem
		},
		data() {
			return {
				statusObj: {
					1: '已审批',
					0: '未审批'
				},
				loading: true,
				statusDesc: {
					1: '入库',
					2: '退还',
					3: '领用'
				},
				detail: {},
				examineStatus: this.$type.examineStatus,
				list: [],
				pathList: ['/property/purchase/info', '/property/rebackPurchase/info','/property/outstore/info'],
				materialApplyType: this.$type.materialApplyType,
				recordInfo: {}
			}
		},
		onLoad(options) {
			this.initDetail(+options.id)
		},
		computed: {
			status() {
				let str = this.recordInfo['申请后状态'] === 1 ? '已' : '待'
				return  str + this.statusDesc[this.recordInfo['申请类型']] 
			}
		},
		methods: {
			async initDetail(id) {
				this.recordInfo = await this.getRecordDetail(id)
				this.detail = await this.getTicketDetail(this.recordInfo.申请类型)
				this.loading = false
				// console.log('list', list)
			},
			getRecordDetail(id) {
				return new Promise(resolve => {
					this.$http.post('/property/apply/info', {id}).then(res => {
						if(res.code === 10000) {
							resolve(res.data)
						}
					})
				})
			},
			getTicketDetail(i) {
				let path = this.pathList[i - 1]
				let obj = i == 1 ? {采购id: this.recordInfo.单据id} : {单据id: this.recordInfo.单据id}
				return new Promise(resolve => {
					this.$http.post(path, obj).then(res => {
						if(res.code === 10000) {
							resolve(res.data)
						}
					})
				})
			}
		}
	}
</script>

<style lang="scss">
@import '../../style/info.scss';
.apply-list-container {
	position: relative;
	top: -180rpx;
}
</style>
